/**
 * @file      pufs_crypto_regs.h
 * @brief     PUFsecurity Crypto Register Definition
 * @copyright 2021 PUFsecurity
 */
/* THIS SOFTWARE IS SUPPLIED BY PUFSECURITY ''AS IS'' AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. TO THE FULLEST
 * EXTENT ALLOWED BY LAW, PUFSECURITY'S TOTAL LIABILITY ON ALL CLAIMS IN
 * ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES,
 * IF ANY, THAT YOU HAVE PAID DIRECTLY TO PUFSECURITY FOR THIS SOFTWARE.
 */

#ifndef __PUFS_CRYPTO_REGS_H__
#define __PUFS_CRYPTO_REGS_H__

#ifdef __cplusplus
extern "C" {
#endif

//----------------------MEMORY MAPPED REGISTER SETTING----------------------//
extern size_t CRYPTO_ADDR_START;
extern size_t CRYPTO_MAP_SIZE;

//----------------------REGISTER SIZES--------------------------------------//
#define SW_KEY_MAXLEN      64 ///< the byte length of CRYPTO_SW_KEY_ADDR
#define DGST_INT_STATE_LEN 64 ///< the byte length of CRYPTO_DGST_(IN|OUT)_ADDR
#define IV_MAXLEN          16

//----------------------MEMORY MAPPED REGISTER STRUCT----------------------//
struct pufs_crypto_regs
{
    volatile uint32_t version;
    volatile uint32_t interrupt;
    volatile uint32_t feature;
    uint32_t _pad1[5];
    volatile uint32_t iv_out[IV_MAXLEN/4];
    volatile uint32_t iv[IV_MAXLEN/4];
    volatile uint32_t sw_key[SW_KEY_MAXLEN/4];
    volatile uint32_t dgst_in[DGST_INT_STATE_LEN/4];
    volatile uint32_t dgst_out[DGST_INT_STATE_LEN/4];
};

//----------------------REGISTER ADDRESSES----------------------------------//
#define CRYPTO_VERSION_ADDR             CRYPTO_ADDR_START
#define CRYPTO_INTRPT_ADDR              (CRYPTO_ADDR_START+0x00000004)
#define CRYPTO_FEATURE_ADDR             (CRYPTO_ADDR_START+0x00000008)
#define CRYPTO_IV_ADDR                  (CRYPTO_ADDR_START+0x00000030)
#define CRYPTO_SW_KEY_ADDR              (CRYPTO_ADDR_START+0x00000040)
#define CRYPTO_DGST_IN_ADDR             (CRYPTO_ADDR_START+0x00000080)
#define CRYPTO_DGST_OUT_ADDR            (CRYPTO_ADDR_START+0x000000C0)

//----------------------REGISTER BIT MASKS----------------------------------//
#define CRYPTO_INTRPT_KWP_MASK          0x00000020
#define CRYPTO_INTRPT_DMA_MASK          0x00000040
#define CRYPTO_INTRPT_HMAC_MASK         0x00000100
#define CRYPTO_INTRPT_CMAC_MASK         0x00002000
#define CRYPTO_INTRPT_KDF_MASK          0x00004000
#define CRYPTO_INTRPT_SP38A_MASK        0x00008000
#define CRYPTO_INTRPT_PKC_MASK          0x00010000
#define CRYPTO_INTRPT_GCM_MASK          0x00020000
#define CRYPTO_FEATURE_AES_MASK         0x00000001
#define CRYPTO_FEATURE_AES_K128_MASK    0x00000002
#define CRYPTO_FEATURE_AES_K192_MASK    0x00000004
#define CRYPTO_FEATURE_AES_K256_MASK    0x00000008
#define CRYPTO_FEATURE_SM4_MASK         0x00000010
#define CRYPTO_FEATURE_SP38A_MASK       0x00000020
#define CRYPTO_FEATURE_CMAC_MASK        0x00000040
#define CRYPTO_FEATURE_HASH_MASK        0x00000080
#define CRYPTO_FEATURE_HMAC_MASK        0x00000100
#define CRYPTO_FEATURE_KDF_MASK         0x00000200
#define CRYPTO_FEATURE_GCM_MASK         0x00000400
#define CRYPTO_FEATURE_XTS_MASK         0x00000800
#define CRYPTO_FEATURE_CCM_MASK         0x00001000
#define CRYPTO_FEATURE_CHACHA_MASK      0x00002000
#define CRYPTO_FEATURE_SBOX_NUM_MASK    0x70000000
#define CRYPTO_FEATURE_AES_MASK_MASK    0x80000000

#ifdef __cplusplus
} // closing brace for extern "C"
#endif

#endif /*__PUFS_CRYPTO_REGS_H__*/
